package com.ruoyi.erp.controller;

import java.math.BigDecimal;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.StaffingSetting;
import com.ruoyi.erp.service.IStaffingSettingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外派属性Controller
 * 
 * @author sauger
 * @date 2022-03-07
 */
@Controller
@RequestMapping("/staffing/setting")
public class StaffingSettingController extends BaseController
{
    private String prefix = "staffing/setting";

    @Autowired
    private IStaffingSettingService staffingSettingService;

    @RequiresPermissions("staffing:setting:view")
    @GetMapping()
    public String setting()
    {
        return prefix + "/setting";
    }

    /**
     * 查询外派属性列表
     */
    @RequiresPermissions("staffing:setting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StaffingSetting staffingSetting)
    {
        startPage();
        List<StaffingSetting> list = staffingSettingService.selectStaffingSettingList(staffingSetting);
        return getDataTable(list);
    }

    /**
     * 导出外派属性列表
     */
    @RequiresPermissions("staffing:setting:export")
    @Log(title = "外派属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StaffingSetting staffingSetting)
    {
        List<StaffingSetting> list = staffingSettingService.selectStaffingSettingList(staffingSetting);
        ExcelUtil<StaffingSetting> util = new ExcelUtil<StaffingSetting>(StaffingSetting.class);
        return util.exportExcel(list, "外派属性数据");
    }


    /**
     * 新增外派属性
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存外派属性
     */
    @RequiresPermissions("staffing:setting:add")
    @Log(title = "外派属性", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StaffingSetting staffingSetting)
    {
        return toAjax(staffingSettingService.insertStaffingSetting(staffingSetting));
    }


    /**
     * 客户、项目弹窗框编辑外派属性
     * @return
     */
    @RequiresPermissions("staffing:setting:edit")
    @GetMapping("/modal/{resourceType}/{resourceId}")
    public String modal(@PathVariable("resourceType") String resourceType, @PathVariable("resourceId") Integer id, ModelMap mmap)
    {
        StaffingSetting setting = staffingSettingService.selectStaffingSettingByResourceWithDefault(resourceType, id);
        mmap.put("staffingSetting", setting);
        if (setting.getId() == null || setting.getId() <= 0){
            return prefix + "/add";
        }else{
            return prefix + "/edit";
        }
    }

    /**
     * 修改外派属性
     */
    @RequiresPermissions("staffing:setting:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        StaffingSetting staffingSetting = staffingSettingService.selectStaffingSettingById(id);
        mmap.put("staffingSetting", staffingSetting);
        return prefix + "/edit";
    }

    /**
     * 修改保存外派属性
     */
    @RequiresPermissions("staffing:setting:edit")
    @Log(title = "外派属性", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StaffingSetting staffingSetting)
    {
        return toAjax(staffingSettingService.updateStaffingSetting(staffingSetting));
    }

    /**
     * 删除外派属性
     */
    @RequiresPermissions("staffing:setting:remove")
    @Log(title = "外派属性", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(staffingSettingService.deleteStaffingSettingByIds(ids));
    }
}
